recreation semantics.
Remove the unpause at the end of xc_linux_restore, and move it to
XendDomainInfo. This is necessary because xenstored now allocates the domain
path when the domain is introduced, which means that the new domain cannot
start running until that introduce is performed and the new devices
configured.
Give restore a separate completion phase in which domain details are stored.
This is required because the domain path is no longer available until after
the introduceDomain call.
TODO: Split the domain introduction into two so that the domain path is
available earlier. At the moment, the domain <-> store channel details are
passed in to xenstored when the domain is introduced, but in the case of
restore it is necessary to wait until the restore is completed before the
channel MFN is available.
Change the interface between XendDomainInfo and XendCheckpoint/image to not
have hideous callbacks through setConsoleRef and setStoreRef. Instead,
image.createImage explicitly returns those values, and XendCheckpoint passes
them through to completeRestore.
Move the purging of the domain path corresponding to a new domain from Xend
to xenstored, since xenstored is now in charge of this path. With the domain
path creation moved to xenstored, Xend cannot remove the path, because watches
may have fired on it already.
Fix the printf statement in xenstored in verbose mode that details the
messages being written. This statement was printing the buffer using %s, but
this buffer has an explicit length field, so we were seeing garbage after the
correct details.
Signed-off-by: Ewan Mellor <ewan@xensource.com>
goto out;
}
- DPRINTF("Domain ready to be unpaused\n");
- op.cmd = DOM0_UNPAUSEDOMAIN;
- op.u.unpausedomain.domain = (domid_t)dom;
- rc = xc_dom0_op(xc_handle, &op);
- if (rc == 0) {
- /* Success: print the domain id. */
- DPRINTF("DOM=%u\n", dom);
- return 0;
- }
-
out:
if ( (rc != 0) && (dom != 0) )
xc_domain_destroy(xc_handle, dom);
dominfo = xd.restore_(vmconfig)
- assert dominfo.store_channel
- assert dominfo.console_channel
- assert dominfo.getDomainPath()
+ store_port = dominfo.getStorePort()
+ console_port = dominfo.getConsolePort()
+
+ assert store_port
+ assert console_port
try:
l = read_exact(fd, sizeof_unsigned_long,
raise XendError(
"not a valid guest state file: pfn count out of range")
- store_evtchn = dominfo.store_channel
- console_evtchn = dominfo.console_channel
-
- cmd = [xen.util.auxbin.pathTo(XC_RESTORE), str(xc.handle()), str(fd),
- str(dominfo.getDomid()), str(nr_pfns),
- str(store_evtchn), str(console_evtchn)]
+ cmd = map(str, [xen.util.auxbin.pathTo(XC_RESTORE),
+ xc.handle(), fd, dominfo.getDomid(), nr_pfns,
+ store_port, console_port])
log.debug("[xc_restore]: %s", string.join(cmd))
- def restoreInputHandler(line, _):
- m = re.match(r"^(store-mfn) (\d+)$", line)
- if m:
- store_mfn = int(m.group(2))
- dominfo.setStoreRef(store_mfn)
- log.debug("IntroduceDomain %d %d %d",
- dominfo.getDomid(),
- store_mfn,
- dominfo.store_channel)
- IntroduceDomain(dominfo.getDomid(),
- store_mfn,
- dominfo.store_channel)
- else:
- m = re.match(r"^(console-mfn) (\d+)$", line)
- if m:
- dominfo.setConsoleRef(int(m.group(2)))
-
- forkHelper(cmd, fd, restoreInputHandler, True)
+ handler = RestoreInputHandler()
+
+ forkHelper(cmd, fd, handler.handler, True)
+
+ if handler.store_mfn is None or handler.console_mfn is None:
+ raise XendError('Could not read store/console MFN')
+
+ dominfo.completeRestore(handler.store_mfn, handler.console_mfn)
return dominfo
except:
raise
+class RestoreInputHandler:
+ def __init__(self):
+ self.store_mfn = None
+ self.console_mfn = None
+
+
+ def handler(self, line, _):
+ m = re.match(r"^(store-mfn) (\d+)$", line)
+ if m:
+ self.store_mfn = int(m.group(2))
+ else:
+ m = re.match(r"^(console-mfn) (\d+)$", line)
+ if m:
+ self.console_mfn = int(m.group(2))
+
+
def forkHelper(cmd, fd, inputHandler, closeToChild):
child = xPopen3(cmd, True, -1, [fd, xc.handle()])
dominfo = self.domain_lookup(domid)
log.info("Domain %s (%d) unpaused.", dominfo.getName(),
dominfo.getDomid())
- return xc.domain_unpause(dom=dominfo.getDomid())
+ return dominfo.unpause()
except Exception, ex:
raise XendError(str(ex))
dominfo = self.domain_lookup(domid)
log.info("Domain %s (%d) paused.", dominfo.getName(),
dominfo.getDomid())
- return xc.domain_pause(dom=dominfo.getDomid())
+ return dominfo.pause()
except Exception, ex:
raise XendError(str(ex))
try:
vm.construct()
vm.initDomain()
- vm.construct_image()
- vm.configure()
vm.storeVmDetails()
vm.storeDomDetails()
vm.refreshShutdown()
assert not xeninfo['dying']
domid = xeninfo['dom']
+ uuid1 = xeninfo['handle']
dompath = GetDomainPath(domid)
if not dompath:
raise XendError(
if not vmpath:
raise XendError(
'No vm path in store for existing domain %d' % domid)
- uuid1_str = xstransact.Read(vmpath, "uuid")
- if not uuid1_str:
+ uuid2_str = xstransact.Read(vmpath, "uuid")
+ if not uuid2_str:
raise XendError(
'No vm/uuid path in store for existing domain %d' % domid)
- uuid1 = uuid.fromString(uuid1_str)
-
- uuid2 = xeninfo['handle']
+ uuid2 = uuid.fromString(uuid2_str)
if uuid1 != uuid2:
raise XendError(
'Uuid in store does not match uuid for existing domain %d: '
- '%s != %s' % (domid, uuid1_str, uuid.toString(uuid2)))
+ '%s != %s' % (domid, uuid2_str, uuid.toString(uuid1)))
- log.info("Recreating domain %d, UUID %s.", domid, uuid1_str)
+ log.info("Recreating domain %d, UUID %s.", domid, uuid2_str)
- vm = XendDomainInfo(uuid2, xeninfo, domid, dompath, True)
+ vm = XendDomainInfo(uuid1, xeninfo, domid, dompath, True)
except Exception, exn:
log.warn(str(exn))
- if priv:
- new_uuid = [0 for i in range(0, 16)]
- else:
- new_uuid = uuid.create()
-
- log.info("Recreating domain %d with new UUID %s.", domid,
- uuid.toString(new_uuid))
+ log.info("Recreating domain %d with UUID %s.", domid,
+ uuid.toString(uuid1))
- vm = XendDomainInfo(new_uuid, xeninfo, domid, dompath, True)
+ vm = XendDomainInfo(uuid1, xeninfo, domid, dompath, True)
vm.removeDom()
+ vm.removeVm()
vm.storeVmDetails()
vm.storeDomDetails()
- if domid != 0:
- # Setup store and console channels
- vm.create_channels()
-
vm.refreshShutdown(xeninfo)
return vm
parseConfig(config))
try:
vm.construct()
- vm.configure()
- vm.create_channels()
vm.storeVmDetails()
- vm.storeDomDetails()
- vm.refreshShutdown()
+ vm.createChannels()
return vm
except:
vm.destroy()
self.image = None
- self.store_channel = None
+ self.store_port = None
self.store_mfn = None
- self.console_channel = None
+ self.console_port = None
self.console_mfn = None
self.state = STATE_DOM_OK
## public:
+ def completeRestore(self, store_mfn, console_mfn):
+
+ self.store_mfn = store_mfn
+ self.console_mfn = console_mfn
+
+ self.introduceDomain()
+ self.create_devices()
+ self.storeDomDetails()
+ self.unpause()
+ self.refreshShutdown()
+
+
def storeVmDetails(self):
to_store = {
'uuid': uuid.toString(self.uuidbytes),
if v:
to_store[k] = str(v)
+ def f(n, v):
+ if v is not None:
+ to_store[n] = str(v)
+
+ f('console/port', self.console_port)
+ f('console/ring-ref', self.console_mfn)
+ f('store/port', self.store_port)
+ f('store/ring-ref', self.store_mfn)
+
to_store.update(self.vcpuDomDetails())
log.debug("Storing domain details: %s", to_store)
return self.dompath
+ def getStorePort(self):
+ """For use only by image.py and XendCheckpoint.py."""
+ return self.store_port
+
+
+ def getConsolePort(self):
+ """For use only by image.py and XendCheckpoint.py"""
+ return self.console_port
+
+
def getVCpuCount(self):
return self.info['vcpus']
"""Get this domain's target memory size, in KiB."""
return self.info['memory_KiB']
- def setStoreRef(self, ref):
- self.store_mfn = ref
- self.storeDom("store/ring-ref", ref)
-
def refreshShutdown(self, xeninfo = None):
# If set at the end of this method, a restart is required, with the
return
elif xeninfo['crashed']:
+ if self.readDom('xend/shutdown_completed'):
+ # We've seen this shutdown already, but we are preserving
+ # the domain for debugging. Leave it alone.
+ return
+
log.warn('Domain has crashed: name=%s id=%d.',
self.info['name'], self.domid)
else:
self.destroy()
+ elif self.dompath is None:
+ # We have yet to manage to call introduceDomain on this
+ # domain. This can happen if a restore is in progress, or has
+ # failed. Ignore this domain.
+ pass
else:
# Domain is alive. If we are shutting it down, then check
# the timeout on that, and destroy it if necessary.
## public:
- def setConsoleRef(self, ref):
- self.console_mfn = ref
- self.storeDom("console/ring-ref", ref)
-
-
def setMemoryTarget(self, target):
"""Set the memory target of this domain.
@param target In MiB.
raise VmError('Creating domain failed: name=%s' %
self.info['name'])
- self.dompath = DOMROOT + str(self.domid)
-
- # Ensure that the domain entry is clean. This prevents a stale
- # shutdown_start_time from killing the domain, for example.
- self.removeDom()
-
# Set maximum number of vcpus in domain
xc.domain_max_vcpus(self.domid, int(self.info['vcpus']))
+
+ def introduceDomain(self):
+ assert self.domid is not None
+ assert self.store_mfn is not None
+ assert self.store_port is not None
+
+ IntroduceDomain(self.domid, self.store_mfn, self.store_port)
+ self.dompath = GetDomainPath(self.domid)
+ assert self.dompath
+
+
def initDomain(self):
log.debug('XendDomainInfo.initDomain: %s %s %s',
self.domid,
xc.domain_setcpuweight(self.domid, self.info['cpu_weight'])
- # XXX Merge with configure_maxmem?
m = self.image.getDomainMemory(self.info['memory_KiB'])
- xc.domain_setmaxmem(self.domid, m)
+ xc.domain_setmaxmem(self.domid, maxmem_kb = m)
xc.domain_memory_increase_reservation(self.domid, m, 0, 0)
cpu = self.info['cpu']
if cpu is not None and cpu != -1:
xc.domain_pincpu(self.domid, 0, 1 << cpu)
- self.info['start_time'] = time.time()
+ self.createChannels()
- log.debug('init_domain> Created domain=%d name=%s memory=%d',
- self.domid, self.info['name'], self.info['memory_KiB'])
+ channel_details = self.image.createImage()
+ self.store_mfn = channel_details['store_mfn']
+ if 'console_mfn' in channel_details:
+ self.console_mfn = channel_details['console_mfn']
- def construct_image(self):
- """Construct the boot image for the domain.
- """
- self.create_channels()
- self.image.createImage()
- IntroduceDomain(self.domid, self.store_mfn, self.store_channel)
+ self.introduceDomain()
+
+ self.create_devices()
+
+ self.info['start_time'] = time.time()
## public:
break
- def eventChannel(self, path=None):
- """Create an event channel to the domain.
-
- @param path under which port is stored in db
+ def createChannels(self):
+ """Create the channels to the domain.
"""
- if path:
- try:
- return int(self.readDom(path))
- except:
- # The port is not yet set, i.e. the channel has not yet been
- # created.
- pass
+ self.store_port = self.createChannel()
+ self.console_port = self.createChannel()
+
+ def createChannel(self):
+ """Create an event channel to the domain.
+ """
try:
- port = xc.evtchn_alloc_unbound(dom=self.domid, remote_dom=0)
+ return xc.evtchn_alloc_unbound(dom=self.domid, remote_dom=0)
except:
log.exception("Exception in alloc_unbound(%d)", self.domid)
raise
- self.storeDom(path, port)
- return port
-
- def create_channels(self):
- """Create the channels to the domain.
- """
- self.store_channel = self.eventChannel("store/port")
- self.console_channel = self.eventChannel("console/port")
def create_configured_devices(self):
for (n, c) in self.info['device']:
self.reconfigureDevice(deviceClass, devid, dev_config)
+ def pause(self):
+ xc.domain_pause(self.domid)
+
+
+ def unpause(self):
+ xc.domain_unpause(self.domid)
+
+
## private:
def restart_check(self):
xd = get_component('xen.xend.XendDomain')
new_dom = xd.domain_create(config)
try:
- xc.domain_unpause(new_dom.getDomid())
+ new_dom.unpause()
except:
new_dom.destroy()
raise
self.config = sxp.merge(['vm', ['image', blcfg]], self.config)
- def configure(self):
- """Configure a vm.
-
- """
- self.configure_maxmem()
- self.create_devices()
-
-
- def configure_maxmem(self):
- if self.image:
- m = self.image.getDomainMemory(self.info['memory_KiB'])
- xc.domain_setmaxmem(self.domid, maxmem_kb = m)
-
-
def send_sysrq(self, key):
asserts.isCharConvertible(key)
"""Entry point to create domain memory image.
Override in subclass if needed.
"""
- self.createDomain()
+ return self.createDomain()
+
def createDomain(self):
"""Build the domain boot image.
log.info("buildDomain os=%s dom=%d vcpus=%d", self.ostype,
self.vm.getDomid(), self.vm.getVCpuCount())
- err = self.buildDomain()
- if err != 0:
- raise VmError('Building domain failed: ostype=%s dom=%d err=%d'
- % (self.ostype, self.vm.getDomid(), err))
+
+ result = self.buildDomain()
+
+ if isinstance(result, dict):
+ return result
+ else:
+ raise VmError('Building domain failed: ostype=%s dom=%d err=%s'
+ % (self.ostype, self.vm.getDomid(), str(result)))
+
def getDomainMemory(self, mem):
"""@return The memory required, in KiB, by the domain to store the
"""Extra cleanup on domain destroy (define in subclass if needed)."""
pass
- def set_vminfo(self, d):
- if d.has_key('store_mfn'):
- self.vm.setStoreRef(d.get('store_mfn'))
- if d.has_key('console_mfn'):
- self.vm.setConsoleRef(d.get('console_mfn'))
-
class LinuxImageHandler(ImageHandler):
ostype = "linux"
def buildDomain(self):
- if self.vm.store_channel:
- store_evtchn = self.vm.store_channel
- else:
- store_evtchn = 0
- if self.vm.console_channel:
- console_evtchn = self.vm.console_channel
- else:
- console_evtchn = 0
+ store_evtchn = self.vm.getStorePort()
+ console_evtchn = self.vm.getConsolePort()
log.debug("dom = %d", self.vm.getDomid())
log.debug("image = %s", self.kernel)
log.debug("ramdisk = %s", self.ramdisk)
log.debug("vcpus = %d", self.vm.getVCpuCount())
- ret = xc.linux_build(dom = self.vm.getDomid(),
- image = self.kernel,
- store_evtchn = store_evtchn,
- console_evtchn = console_evtchn,
- cmdline = self.cmdline,
- ramdisk = self.ramdisk)
- if isinstance(ret, dict):
- self.set_vminfo(ret)
- return 0
- return ret
+ return xc.linux_build(dom = self.vm.getDomid(),
+ image = self.kernel,
+ store_evtchn = store_evtchn,
+ console_evtchn = console_evtchn,
+ cmdline = self.cmdline,
+ ramdisk = self.ramdisk)
class VmxImageHandler(ImageHandler):
self.dmargs += self.configVNC(imageConfig)
- def createImage(self):
- """Create a VM for the VMX environment.
- """
- self.createDomain()
-
def buildDomain(self):
# Create an event channel
self.device_channel = xc.evtchn_alloc_unbound(dom=self.vm.getDomid(),
remote_dom=0)
log.info("VMX device model port: %d", self.device_channel)
- if self.vm.store_channel:
- store_evtchn = self.vm.store_channel
- else:
- store_evtchn = 0
+
+ store_evtchn = self.vm.getStorePort()
log.debug("dom = %d", self.vm.getDomid())
log.debug("image = %s", self.kernel)
log.debug("memsize = %d", self.vm.getMemoryTarget() / 1024)
log.debug("vcpus = %d", self.vm.getVCpuCount())
- ret = xc.vmx_build(dom = self.vm.getDomid(),
- image = self.kernel,
- control_evtchn = self.device_channel,
- store_evtchn = store_evtchn,
- memsize = self.vm.getMemoryTarget() / 1024,
- vcpus = self.vm.getVCpuCount())
- if isinstance(ret, dict):
- self.set_vminfo(ret)
- return 0
- return ret
+ return xc.vmx_build(dom = self.vm.getDomid(),
+ image = self.kernel,
+ control_evtchn = self.device_channel,
+ store_evtchn = store_evtchn,
+ memsize = self.vm.getMemoryTarget() / 1024,
+ vcpus = self.vm.getVCpuCount())
+
# Return a list of cmd line args to the device models based on the
# xm config file
if (out->inhdr) {
if (verbose)
- xprintf("Writing msg %s (%s) out to %p\n",
+ xprintf("Writing msg %s (%.*s) out to %p\n",
sockmsg_string(out->hdr.msg.type),
+ out->hdr.msg.len,
out->buffer, conn);
ret = conn->write(conn, out->hdr.raw + out->used,
sizeof(out->hdr) - out->used);
corrupt(conn, "Can't find child '%s' in %s", childname, node->name);
}
+
+static int _rm(struct connection *conn, struct node *node, const char *name)
+{
+ /* Delete from parent first, then if something explodes fsck cleans. */
+ struct node *parent = read_node(conn, get_parent(name));
+ if (!parent) {
+ send_error(conn, EINVAL);
+ return 0;
+ }
+
+ if (!delete_child(conn, parent, basename(name))) {
+ send_error(conn, EINVAL);
+ return 0;
+ }
+
+ delete_node(conn, node);
+ return 1;
+}
+
+
static void do_rm(struct connection *conn, const char *name)
{
- struct node *node, *parent;
+ struct node *node;
name = canonicalize(conn, name);
node = get_node(conn, name, XS_PERM_WRITE);
return;
}
- /* Delete from parent first, then if something explodes fsck cleans. */
- parent = read_node(conn, get_parent(name));
- if (!parent) {
- send_error(conn, EINVAL);
- return;
+ if (_rm(conn, node, name)) {
+ add_change_node(conn->transaction, name, true);
+ fire_watches(conn, name, true);
+ send_ack(conn, XS_RM);
}
+}
- if (!delete_child(conn, parent, basename(name))) {
- send_error(conn, EINVAL);
+
+void internal_rm(const char *name)
+{
+ struct node *node = read_node(NULL, name);
+ if (!node) {
return;
}
-
- delete_node(conn, node);
- add_change_node(conn->transaction, name, true);
- fire_watches(conn, name, true);
- send_ack(conn, XS_RM);
+ _rm(NULL, node, name);
}
+
static void do_get_perms(struct connection *conn, const char *name)
{
struct node *node;
struct connection *new_connection(connwritefn_t *write, connreadfn_t *read);
+
+void internal_rm(const char *name);
+
+
/* Is this a valid node name? */
bool is_valid_nodename(const char *node);
list_add(&domain->list, &domains);
talloc_set_destructor(domain, destroy_domain);
+ internal_rm(domain->path);
+
/* Tell kernel we're interested in this event. */
bind.remote_domain = domid;
bind.remote_port = port;